<?php

namespace app\widgets;

use Yii;
use yii\widgets\LinkPager;

class LinkPagerExt extends LinkPager
{
    public function run()
    {
//        $totalCount = $this->pagination->totalCount;
//        $totalPage = $this->pagination->pageCount;
//        $totalPage = $this->pagination->getPage();
//        $goUrl = $this->getGoUrl();

        // parent::run
        if ($this->registerLinkTags) {
            $this->registerLinkTags();
        }

        return $this->render('link-pager-ext', ['pagination' => $this->pagination, 'linkPager' => $this->renderPageButtons(), 'goUrl' => $this->getGoUrl()]);


//        echo "<div class='pagination-summary-left'>共 $totalCount 条数据</div>";
//
//        parent::run();
//
//        if ($totalPage > 10) {
//            echo "<input type='button' class='btn btn-primary pagination-page-btn' value='跳转' onclick='paginationGo()'>";
//            $page = $this->pagination->getPage() + 1;
//            echo "<input type='number'  id='pagination_page_input' class='pagination-page-input' value='$page'>";
//            echo "<script type='application/javascript'>
//                function paginationGo() {
//                    var goPage = $('#pagination_page_input').val();
//                    if(goPage<1){
//                        goPage=1;
//                    }
//                    if(goPage>$totalPage){
//                        goPage=$totalPage;
//                    }
//                    window.location.href='{$goUrl}page='+goPage;
//                }
//            </script>";
//            echo "<div class='pagination-summary-right'>共 $totalPage 页</div>";
//        }
    }

    private function getGoUrl()
    {
        $params = Yii::$app->request->getQueryParams();
        unset($params[$this->pagination->pageParam]);
        unset($params[$this->pagination->pageSizeParam]);
        $params[0] = $this->pagination->route === null ? Yii::$app->controller->getRoute() : $this->pagination->route;
        $urlManager = $this->pagination->urlManager === null ? Yii::$app->getUrlManager() : $this->pagination->urlManager;
        $url = $urlManager->createUrl($params);
        if (count($params) > 1) {
            $url = $url . '&';
        } else {
            $url = $url . '?';
        }
        return $url;
    }
}